using System.Data;
using myproject.method;
using supermarket.method;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace supermarket
{
    public partial class admin : Form
    {
        Classvd vd = new Classvd(4, Classvd.CodeType.Alphas); 

        public admin()
        {
            InitializeComponent();
            RefreshVerificationCode();
        }
        //确定
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.code.Text.ToLower() != vd.CheckCode.ToLower())
            {
                MessageBox.Show("验证码错误！", "提示框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Classuser us = new Classuser();
            var (success, role, tip) = us.AdminSelect(textadminname.Text, textadminpwd.Text);
            if (success)
            {
                supmain frm = new supmain(textadminname.Text,role,tip);
                this.Hide();
                clear();
                frm.Show();
            }
            else
            {
                MessageBox.Show("登录失败！用户名或密码错误。");
            }
        }


        public void clear()
        {
            textadminname.Text = "";
            textadminpwd.Text = "";
            code.Text = "";
        }
        //清空
        private void button2_Click(object sender, EventArgs e)
        {
            textadminname.Text = "";
            textadminpwd.Text = "";
            code.Text = "";
        }

        //取消
        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            RefreshVerificationCode();
        }

        private void pbconfir_Click_1(object sender, EventArgs e)
        {
            RefreshVerificationCode();
        }

        private void label4_Click(object sender, EventArgs e)
        {
            RefreshVerificationCode();
        }

        private void admin_Load(object sender, EventArgs e)
        {
            RefreshVerificationCode();
        }

        private void RefreshVerificationCode()
        {
            vd = new Classvd(4, Classvd.CodeType.Alphas);  // 重新创建验证码对象
            pbconfir.Image = Bitmap.FromStream(vd.CreateCheckCodeImage());    //生成图片验证码，加载到图片框中
        }
    }
}